<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>HDCMS 数据库配置</title>
    <link href="http://cdn.bootcss.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet">
    <script src="http://cdn.bootcss.com/jquery/2.2.4/jquery.min.js"></script>
    <link href="http://cdn.bootcss.com/font-awesome/4.6.3/css/font-awesome.min.css" rel="stylesheet">
    <script src="http://cdn.bootcss.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
</head>
<body style="background: #33b2e2">
<div style="width:1100px;margin: 10px auto;">
    <div style="background: url(http://dev.hdcms.com/resource/images/logo.png) no-repeat;background-size:contain;height:80px;"></div>
    <br/>
    <div class="panel panel-default">
        <nav class="navbar navbar-default alert-info" style="border-radius: 0px;">
            <div class="container-fluid">
                <div class="navbar-header">
                    <a class="navbar-brand" href="#"><strong>HDCMS 百分百开源免费,可用于任意商业项目!</strong>
                        <small class="text-info">使用高效的HDPHP框架构建</small>
                    </a>
                </div>
                <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
                    <ul class="nav navbar-nav navbar-right">
                        <li><a href="http://www.houdunwang.com" target="_blank">培训</a></li>
                        <li><a href="http://www.hdcms.com" target="_blank">官网</a></li>
                    </ul>
                </div>
            </div>
        </nav>
        <div class="panel-body">
            <div class="col-xs-3">
                <div class="progress">
                    <div class="progress-bar progress-bar-striped progress-bar-danger active" style="width: 60%;">
                        60%
                    </div>
                </div>
                <ul class="list-group">
                    <li class="list-group-item"><strong>安装步骤</strong></li>
                    <li class="list-group-item"><i class="fa fa-copyright"></i> 安装协议</li>
                    <li class="list-group-item"><i class="fa fa-pencil-square-o"></i> 环境检测</li>
                    <li class="list-group-item" style="background: #dff0d8"><i class="fa fa-database"></i> 数据库配置</li>
                    <li class="list-group-item"><i class="fa fa-cloud-download"></i> 下载软件包</li>
                    <li class="list-group-item"><i class="fa fa-check-circle"></i> 完成</li>
                </ul>
            </div>
            <form class="form-horizontal" method="post">
                <div class="col-xs-9">
                    <div class="panel panel-default">
                        <div class="panel-heading">
                            数据库配置
                        </div>
                        <div class="panel-body" style="padding: 10px;">

                            <div class="form-group">
                                <label class="col-sm-2 control-label">主机</label>
                                <div class="col-sm-8">
                                    <input type="text" class="form-control" name="host" value="127.0.0.1" required="required">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">数据库</label>
                                <div class="col-sm-8">
                                    <input type="text" class="form-control" name="database" required="required">
                                    <span class="help-block">数据库不存在时系统将尝试创建,但帐号没有权限时创建将失败</span>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">用户名</label>
                                <div class="col-sm-8">
                                    <input type="text" class="form-control" name="user" required="required">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">密码</label>
                                <div class="col-sm-8">
                                    <input type="password" class="form-control" name="password">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">表前缀</label>
                                <div class="col-sm-8">
                                    <input type="text" class="form-control" name="prefix" value="hd_" required="required" placeholder="表前缀只能为字母或下划线">
                                </div>
                            </div>

                        </div>
                    </div>
                    <div class="panel panel-default">
                        <div class="panel-heading">
                            系统帐号
                        </div>
                        <div class="panel-body" style="padding: 10px;">

                            <div class="form-group">
                                <label class="col-sm-2 control-label">帐号</label>
                                <div class="col-sm-8">
                                    <input type="text" class="form-control" name="username" value="admin" required="required">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">密码</label>
                                <div class="col-sm-8">
                                    <input type="password" class="form-control" name="upassword" required="required">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">确认密码</label>
                                <div class="col-sm-8">
                                    <input type="password" class="form-control" name="upassword2" required="required">
                                </div>
                            </div>
                        </div>
                    </div>

                    <a href="javascript:history.back()" class="btn btn-success">返回</a>
                    <a href="javascript:;" class="btn btn-primary" onclick="post()">继续</a>
                </div>
            </form>
        </div>
    </div>
    <div class="text-center" style="color:#ffffff;"> ©2010 - 2019 hdcms.com Inc.</div>
</div>
</body>
</html>
<script>
    function post() {
        var msg = '';
        if (!/^[a-z_]+$/i.test($.trim($("[name='prefix']").val()))) {
            msg = '表前缀只能为字母或下划线';
        }
        if ($.trim($("[name='upassword']").val()) != $.trim($("[name='upassword2']").val())) {
            msg = '系统管理员的两次密码不一致';
        }
        $("[name]").each(function () {
            if ($(this).attr('name') != 'password' && $.trim($(this).val()) == '') {
                msg = $(this).parent().prev().text() + "不能为空";
            }
        });

        if (msg) {
            alert(msg);
            return false;
        }
        $.post('?a=database', $('form').serialize(), function (res) {
            if (res.valid == 1) {
                location.href = '?a=download';
            } else {
                alert(res.message);
            }
        }, 'json');
    }
</script>